package code.structure.module.configs.cmd
{
	import flash.utils.Dictionary;
	
	import code.structure.module.configs.ConfigModel;
	import code.structure.module.configs.data.task.TaskConfigData;
	import code.structure.module.configs.data.task.TaskRewardConfig;
	import code.structure.module.configs.data.task.TaskSubConfigData;

	/**
	 * 解析任务
	 * @author CYoung
	 * 2014-7-27下午3:22:12
	 */
	public class AnalysisTask
	{
		/** 任务字典 */
		private var _dictionary:Dictionary;
		/** 子任务字典 */
		private var _subDictionary:Dictionary;
		
		public function AnalysisTask(data:Object, subData:Object, config:ConfigModel)
		{
			parserSubData(subData);
			parserData(data, config);
		}
		//解析子任务数据
		private function parserSubData(subData:Object):void
		{
			_subDictionary = new Dictionary();
			var sub:TaskSubConfigData;
			for each (var i:Object in subData) {
				sub = new TaskSubConfigData(i);
				_subDictionary[sub.id] = sub;
			}
		}
		//解析任务数据
		private function parserData(data:Object, config:ConfigModel):void
		{
			_dictionary = new Dictionary();
			var task:TaskConfigData;
			for each (var i:Object in data) {
				task = new TaskConfigData(i);
				_dictionary[task.id] = task;
				for (var j:int = 0; j < task.subTaskList.length; j++) 
					task.subTaskList[j] = _subDictionary[int(task.subTaskList[j])];
				for (var m:int = 0; m < task.rewardList.length; m++) {
					task.rewardList[m] = new TaskRewardConfig(task.rewardList[m]);
					task.rewardList[m].data = config.analysisItem.getItemConfigDataById(task.rewardList[m].id);
				}
			}
			_subDictionary = null;
		}
		/**
		 * 通过ID获取任务数据
		 */		
		public function getTaskConfigById(id:String):TaskConfigData{
			return _dictionary[id];
		}
	}
}